package com.tour.tour.config;

import com.tour.tour.Interceptor.LoginInterceptor;
import com.tour.tour.Interceptor.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author YounGCY
 * @date 2023-5-16 下午 4:32
 * @description
 */
@Configuration
@CrossOrigin
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/hotel/**",
                        "/post/**",
                        "/spots/**",
                        "/route/**",
                        "/user/login",
                        "/user/code",
                        "/user/register",
                        "/user/forgot"
                ).order(1);
        // 刷新token拦截器
        // token刷新的拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
